\doxysection{x\+Task\+Create\+Restricted }
\hypertarget{group__x_task_create_restricted}{}\label{group__x_task_create_restricted}\index{xTaskCreateRestricted@{xTaskCreateRestricted}}
task. h 
\begin{DoxyPre}
 BaseType\_t xTaskCreateRestricted( TaskParameters\_t *pxTaskDefinition, TaskHandle\_t *pxCreatedTask );\end{DoxyPre}


Only available when config\+SUPPORT\+\_\+\+DYNAMIC\+\_\+\+ALLOCATION is set to 1.

x\+Task\+Create\+Restricted() should only be used in systems that include an MPU implementation.

Create a new task and add it to the list of tasks that are ready to run. The function parameters define the memory regions and associated access permissions allocated to the task.

See x\+Task\+Create\+Restricted\+Static() for a version that does not use any dynamic memory allocation.


\begin{DoxyParams}{Parameters}
{\em px\+Task\+Definition} & Pointer to a structure that contains a member for each of the normal x\+Task\+Create() parameters (see the x\+Task\+Create() API documentation) plus an optional stack buffer and the memory region definitions.\\
\hline
{\em px\+Created\+Task} & Used to pass back a handle by which the created task can be referenced.\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
pd\+PASS if the task was successfully created and added to a ready list, otherwise an error code defined in the file \doxylink{projdefs_8h_source}{projdefs.\+h}
\end{DoxyReturn}
Example usage\+: 
\begin{DoxyPre}
// Create an TaskParameters\_t structure that defines the task to be created.
static const TaskParameters\_t xCheckTaskParameters =
\{
    vATask,     // pvTaskCode -\/ the function that implements the task.
    "{}ATask"{},    // pcName -\/ just a text name for the task to assist debugging.
    100,        // usStackDepth -\/ the stack size DEFINED IN WORDS.
    NULL,       // pvParameters -\/ passed into the task function as the function parameters.
    ( 1UL | portPRIVILEGE\_BIT ),// uxPriority -\/ task priority, set the portPRIVILEGE\_BIT if the task should run in a privileged state.
    cStackBuffer,// puxStackBuffer -\/ the buffer to be used as the task stack.

    // xRegions -\/ Allocate up to three separate memory regions for access by
    // the task, with appropriate access permissions.  Different processors have
    // different memory alignment requirements -\/ refer to the FreeRTOS documentation
    // for full information.
    \{
        // Base address                 Length  Parameters
        \{ cReadWriteArray,              32,     portMPU\_REGION\_READ\_WRITE \},
        \{ cReadOnlyArray,               32,     portMPU\_REGION\_READ\_ONLY \},
        \{ cPrivilegedOnlyAccessArray,   128,    portMPU\_REGION\_PRIVILEGED\_READ\_WRITE \}
    \}
\};

int \doxylink{main_8c_a840291bc02cba5474a4cb46a9b9566fe}{main( void )}
\{
TaskHandle\_t xHandle;

    // Create a task from the const structure defined above.  The task handle
    // is requested (the second parameter is not NULL) but in this case just for
    // demonstration purposes as its not actually used.
    xTaskCreateRestricted( \&xRegTest1Parameters, \&xHandle );

    // Start the scheduler.
    vTaskStartScheduler();

    // Will only get here if there was insufficient memory to create the idle
    // and/or timer task.
    for( ;; );
\}
   \end{DoxyPre}


task. h 
\begin{DoxyPre}
 void vTaskAllocateMPURegions( TaskHandle\_t xTask, const MemoryRegion\_t * const pxRegions );\end{DoxyPre}


Memory regions are assigned to a restricted task when the task is created by a call to x\+Task\+Create\+Restricted(). These regions can be redefined using v\+Task\+Allocate\+MPURegions().


\begin{DoxyParams}{Parameters}
{\em x\+Task} & The handle of the task being updated.\\
\hline
{\em x\+Regions} & A pointer to an Memory\+Region\+\_\+t structure that contains the new memory region definitions.\\
\hline
\end{DoxyParams}
Example usage\+: 
\begin{DoxyPre}
// Define an array of MemoryRegion\_t structures that configures an MPU region
// allowing read/write access for 1024 bytes starting at the beginning of the
// ucOneKByte array.  The other two of the maximum 3 definable regions are
// unused so set to zero.
static const MemoryRegion\_t xAltRegions[ portNUM\_CONFIGURABLE\_REGIONS ] =
\{
    // Base address     Length      Parameters
    \{ ucOneKByte,       1024,       portMPU\_REGION\_READ\_WRITE \},
    \{ 0,                0,          0 \},
    \{ 0,                0,          0 \}
\};

void vATask( void *pvParameters )
\{
    // This task was created such that it has access to certain regions of
    // memory as defined by the MPU configuration.  At some point it is
    // desired that these MPU regions are replaced with that defined in the
    // xAltRegions const struct above.  Use a call to vTaskAllocateMPURegions()
    // for this purpose.  NULL is used as the task handle to indicate that this
    // function should modify the MPU regions of the calling task.
    vTaskAllocateMPURegions( NULL, xAltRegions );

    // Now the task can continue its function, but from this point on can only
    // access its stack and the ucOneKByte array (unless any other statically
    // defined or shared regions have been declared elsewhere).
\}
   \end{DoxyPre}
 